package com.sky.controller.admin;

import com.sky.dto.AddDishDTO;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishPageQueryItemVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品管理")
@RequestMapping("admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    @ApiOperation("新增菜品")
    @PostMapping()
    public Result addDish(@RequestBody AddDishDTO addDishDTO){
        dishService.addDish(addDishDTO);
        return Result.success();
    }
    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result<PageResult<DishPageQueryItemVO>>page(DishPageQueryDTO dto){
        PageResult<DishPageQueryItemVO>page= dishService.page(dto);
        return Result.success(page);
    }
    @ApiOperation("删除菜品")
    @DeleteMapping
    public Result delete(@RequestParam("ids")List<Long> ids){
        dishService.delete(ids);
        return Result.success();
    }
    @ApiOperation("修改回显")
    @GetMapping("{id}")
    public Result<DishVO>getById(@PathVariable("id")Long id){
        DishVO vo=dishService.getById(id);
        return Result.success(vo);
    }
    @ApiOperation("修改菜品")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }
    @ApiOperation("增加套餐回显")
    @GetMapping("/list")
    public Result addsetmeal(Long categoryId){
       List<Dish> dish= dishService.addsetmeal(categoryId);
        return Result.success(dish);

    }



}
